package com.ruoyi.web.controller.owner;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PropertyFamily;
import com.ruoyi.system.service.IPropertyFamilyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 家庭成员Controller
 * 
 * @author ruoyi
 * @date 2025-10-27
 */
@RestController
@RequestMapping("/system/family")
public class PropertyFamilyController extends BaseController
{
    @Autowired
    private IPropertyFamilyService propertyFamilyService;

    /**
     * 查询家庭成员列表
     */
    @PreAuthorize("@ss.hasPermi('system:family:list')")
    @GetMapping("/list")
    public TableDataInfo list(PropertyFamily propertyFamily)
    {
        startPage();
        List<PropertyFamily> list = propertyFamilyService.selectPropertyFamilyList(propertyFamily);
        return getDataTable(list);
    }

    /**
     * 导出家庭成员列表
     */
    @PreAuthorize("@ss.hasPermi('system:family:export')")
    @Log(title = "家庭成员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PropertyFamily propertyFamily)
    {
        List<PropertyFamily> list = propertyFamilyService.selectPropertyFamilyList(propertyFamily);
        ExcelUtil<PropertyFamily> util = new ExcelUtil<PropertyFamily>(PropertyFamily.class);
        util.exportExcel(response, list, "家庭成员数据");
    }

    /**
     * 获取家庭成员详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:family:query')")
    @GetMapping(value = "/{familyId}")
    public AjaxResult getInfo(@PathVariable("familyId") Long familyId)
    {
        return success(propertyFamilyService.selectPropertyFamilyByFamilyId(familyId));
    }

    /**
     * 新增家庭成员
     */
    @PreAuthorize("@ss.hasPermi('system:family:add')")
    @Log(title = "家庭成员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PropertyFamily propertyFamily)
    {
        return toAjax(propertyFamilyService.insertPropertyFamily(propertyFamily));
    }

    /**
     * 修改家庭成员
     */
    @PreAuthorize("@ss.hasPermi('system:family:edit')")
    @Log(title = "家庭成员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PropertyFamily propertyFamily)
    {
        return toAjax(propertyFamilyService.updatePropertyFamily(propertyFamily));
    }

    /**
     * 删除家庭成员
     */
    @PreAuthorize("@ss.hasPermi('system:family:remove')")
    @Log(title = "家庭成员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{familyIds}")
    public AjaxResult remove(@PathVariable Long[] familyIds)
    {
        return toAjax(propertyFamilyService.deletePropertyFamilyByFamilyIds(familyIds));
    }
}
